package com.kfm.jdbc.day0324;

import java.sql.*;

public class Test {

    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/store?user=root&password=");
            String sql = "select e.id eid,e.first_name ename, e.salary esal, sd.name dname from s_emp e join s_dept sd on e.dept_id = sd.id";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            ResultSet resultSet = preparedStatement.executeQuery();
            ResultSetMetaData metaData = resultSet.getMetaData();
            for (int i = 0; i < metaData.getColumnCount(); i++) {
                System.out.println(metaData.getColumnLabel(i + 1));
                System.out.println(metaData.getColumnName(i + 1));
                System.out.println(metaData.getTableName(i + 1));
                System.out.println(metaData.getCatalogName(i + 1));
            }
        } catch (ClassNotFoundException | SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
